package com.huizhonglm.diap.ui.wallet;

import android.os.Bundle;
import android.widget.ListView;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.QueueInfo;
import com.huizhonglm.diap.core.utils.UserUtil;
import com.huizhonglm.diap.presenters.wallet.QueryQueuePresenter;
import com.huizhonglm.diap.ui.BaseActivity;
import com.huizhonglm.diap.ui.wallet.iView.QueryQueueIView;
import com.huizhonglm.diap.widget.LoadView;

import java.util.List;

/**
 * 查询排队返现
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-22 13:42
 */
public class QueryQueueActivity extends BaseActivity implements QueryQueueIView, LoadView.OnLoadAgainListener {

    private ListView mListView;
    private LoadView loadView;

    private QueryQueuePresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query_queue);
        setBackEvent(this, null);
        mPresenter = new QueryQueuePresenter(this);
        assignViews();
    }

    @Override
    protected void onResume() {
        super.onResume();
        onLoadAgain();
    }

    @Override
    protected void assignViews() {
        loadView = (LoadView) findViewById(R.id.load_view);
        mListView = (ListView) findViewById(R.id.queue_list);
        loadView.setDataView(mListView, this);
    }

    @Override
    public void onLoadAgain() {
        loadView.showProgress();
        mPresenter.loadData(UserUtil.getUserId());
    }

    @Override
    public void onLoadDataSuccess(List<QueueInfo> data) {
        if (!EmptyUtil.isEmpty(data)) {
            QueryQueueAdapter adapter = new QueryQueueAdapter(this, data);
            mListView.setAdapter(adapter);
            loadView.showDataView();
        } else {
            loadView.showEmptyView("当前无排队信息");
        }
    }

    @Override
    public void onLoadDataFailure() {
        loadView.showErrorView();
    }
}
